﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RegisterationCommon.Common;
using System.Data;
using RegisterationCommon.School;
using RegisterationCommon.Student;
using RegisterationCommon.Education;
using System.IO;
using RegisterationCommon;
using RegisterationCommon.Preschools;

namespace RegisterationSystem.Space_Preschools
{
    public partial class main : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
                if (Request.Form["action"] != "")
                {
                    switch (Request.Form["action"])
                    {
                        case "updstatusbyid":
                            UpdStatusByID();
                            break;
                        case "delstudentlist":
                            DelStudentList();
                            break;
                        case "delstudentByID":
                            DelStudentByID();
                            break;            
                        case "pswdreset":
                            UpdStudentPswdReset();
                            break;
                        case "GetPreschoolsID":
                            GetPreschoolsID();
                            break;
                    }
                }

                //取到用户名
               // string AccountName = Request.QueryString["AccountName"];
                b();
            }
        }
        public DataTable dt = new DataTable();
        public DataSet ds = new DataSet();
        public void b()
        {
            string AccountName = Request.QueryString["AccountName"];
            ds = SqlHelp.ExecuteDataset(SqlHelp.constr, "SELECT     dbo.Students.TrueName as 学生姓名,dbo.Preschools.Name as 幼儿园名称, dbo.SchoolInfo.Name AS 学校名称 FROM   dbo.Preschools INNER JOIN dbo.Students ON dbo.Preschools.ID = dbo.Students.PreschoolsID inner join dbo.SchoolInfo on Students.SchID=SchoolInfo.ID where Preschools.AccountName='" + AccountName + "'", CommandType.Text, null);
        }

        void UpdStudentPswdReset()
        {
            string id = Request.Form["id"].ToString();
            string AccountPswd = Request.Form["StudentPswd"].ToString();
            //StudentInfo s = new StudentInfo();
            RegisterationCommon.Preschools.Preschools s = new RegisterationCommon.Preschools.Preschools();
            s.MdfAccountPwd(Convert.ToInt32(id), BaseLibrary.ConvertToMD5(AccountPswd.ToLower()));
        }

        //根据ID删除
        void DelStudentByID()
        {
            string id = Request.Form["id"];
            string deletereason = Request.Form["deletereason"];
            Preschools s = new Preschools();
            s.ID = Convert.ToInt32(id);
            //s.IsDelete = true;
            //s.DeleteReason = deletereason;
            //s.DeleteorGiveupStatic();
        }
        //批量删除
        void DelStudentList()
        {
            //获删除改ID
            string idlist = Request.Form["id"];
            string deletereason = Request.Form["deletereason"];
            string[] ids = idlist.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < ids.Length; i++)
            {
                Preschools s = new Preschools();
                s.ID = Convert.ToInt32(ids[i]);
                //s.IsDelete = true;
                //s.DeleteReason = deletereason;
                //s.DeleteorGiveupStatic();
            }
        }



        //根据ID修改学生状态
        void UpdStatusByID()
        {
            //获取修改ID
            string id = Request.Form["id"];
            Preschools s = new Preschools();
            s.ID = Convert.ToInt32(id);
            //s.Status = Convert.ToInt32(status);
            //s.MdfStatus();

        }

        /// <summary>
        /// 绑定招生数
        /// </summary>
        void Bind()
        {
            //绑定公告
            Repeater2.DataSource = DBAction.GetDTFromSQL("select top 6 * from Notice where (Recrive=0 or Recrive=2) and Status=0 order by id desc");
            Repeater2.DataBind();

            RParams RP = new RParams();

            RP.Add("IsRecord", true, SqlDbType.Bit);
            RP.Add("IsDelete", false, SqlDbType.Bit);
            RP.Add("IsMatured", true, SqlDbType.Bit);
            RP.Add("Status", 2, SqlDbType.Int);
            RP.Add("SchID", Cookies.Get("SchID"), SqlDbType.Int);

        }

        void GetPreschoolsID()
        {
            string id = Request.Form["id"].ToString();
            string StudentPswd = Request.Form["StudentPswd"].ToString();
            Preschools s = new Preschools();
            s.MdfAccountPwd(Convert.ToInt32(id), BaseLibrary.ConvertToMD5(StudentPswd.ToLower()));
        }
    }
}